package com.example.my_flea_street.Mapper;

import com.example.my_flea_street.bean.Info;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserViewMapper {

    @Select("SELECT b.id ,b.release_time,b.text,b.pic,b.category,b.key_word,b.is_settled,b.is_banned,b.user_id,a.name,a.sex,a.head FROM user a,information b WHERE a.id=b.user_id and a.id=#{user_id} and b.is_settled=#{is_settled} ORDER BY release_time desc")
    Page<Info> getInfo(@Param("user_id") int id,@Param("is_settled") int type);
    @Select("SELECT count(*) FROM user a,information b WHERE a.id=b.user_id and a.id=#{user_id} and b.is_settled=#{is_settled} ORDER BY release_time desc")
    int getSettledCount(@Param("user_id") int user_id,@Param("is_settled") int type);
    @Delete("delete from information where id=#{id}")
    void deleteInfo(@Param("id") int id);
    @Update("update information set is_settled=1 where id=#{id}")
    void settledInfo(@Param("id") int id);
    @Insert("insert into is_repored_user(release_time,pic,text,user_id) values(#{release_time},#{pic},#{text},#{user_id})")
    @Options(useGeneratedKeys = true)
    void report(@Param("user_id") int user_id,@Param("text")String text,
                @Param("release_time")String release_time, @Param("pic") String pic);
}
